package org.example.easybuy.service.impl;

import org.example.easybuy.service.CarService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;


public class RedisKeyListener extends KeyExpirationEventMessageListener {

    @Autowired
    private CarService carService;

    Logger logger=  LoggerFactory.getLogger(RedisKeyListener.class);
    public RedisKeyListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        //如果键值以order开头
        if(message.toString().startsWith("order"))
        {
            //更改订单的状态
            carService.doChangeOrder(message.toString());
            logger.info("过期的key"+message.toString());
        }
    }


}
